//
//  SYMainViewController.swift
//  SYWeibo
//
//  Created by Eric on 16/7/19.
//  Copyright © 2016年 Eric. All rights reserved.
//

import UIKit

class SYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = SYTabBar()
//        tabBar.syDelegate = self
        tabBar.closure = {[weak self] in
            
            let composeView = SYComposeView()
            composeView.composeViewShow(self!)
            
            
            
//            self?.view .addSubview(composeView)
            
            
//        let composeVc = SYComposeViewController()
//            //主界面 跳转撰写界面
//            self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil )
        }
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(SYHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(SYMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(SYDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(SYProfileViewController(), title: "我", imgName: "tabbar_profile")
    }
    
    func addChildViewController(VC: UIViewController, title: String,imgName: String) {
        //设置导航标题
        VC.title = title
        //设置图片
        VC.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置颜色
        VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //选择渲染方式
        VC.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //添加自控制器
        addChildViewController(UINavigationController(rootViewController: VC))
    }
    
    
}
